package com.laicunba.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.laicunba.pojo.FinancingTargetDO;
import com.laicunba.pojo.FinancingTargetPositionDO;
import com.laicunba.pojo.vo.FinancingTargetPositionVO;
import com.laicunba.pojo.vo.PositionConditionVO;
import com.laicunba.service.FinancingTargetPositionService;
import com.laicunba.service.FinancingTargetService;
import com.laicunba.util.StringUtil;

@Service
public class FinancingTargetPositionServiceImpl extends BaseServiceImpl implements FinancingTargetPositionService {

	@Autowired
	private FinancingTargetService financingTargetService;

	@Override
	public boolean create(FinancingTargetPositionDO financingTargetPosition) {
		return super.create(financingTargetPosition);
	}

	@Override
	public List<FinancingTargetPositionVO> getFinancingTargetPositionVOList(FinancingTargetPositionVO positionVO) {
		List<FinancingTargetPositionVO> financingTargetPositionVOList = queryDao.selectList("FINANCING_TARGET_POSITION.findFinancingTargetPositionList", positionVO);
//		List<FinancingTargetPositionDO> financingTargetPositionDOList = queryDao.selectList("FINANCING_TARGET_POSITION.findFinancingTargetPositionList", condition);
//		List<FinancingTargetPositionVO> financingTargetPositionVOList = new ArrayList<FinancingTargetPositionVO>();
//		FinancingTargetPositionVO financingTargetPositionVO = null;
//		FinancingTargetDO financingTargetDO = null;
//		if (financingTargetPositionDOList != null && financingTargetPositionDOList.size() > 0) {
//			for (FinancingTargetPositionDO financingTargetPositionDO : financingTargetPositionDOList) {
//				if (financingTargetPositionDO != null && StringUtil.isNotEmpty(financingTargetPositionDO.getFinancingTargetId())) {
//					financingTargetPositionVO = new FinancingTargetPositionVO();
//					financingTargetPositionVO.setId(financingTargetPositionDO.getId());
//					financingTargetPositionVO.setPosition(financingTargetPositionDO.getPosition());
//					financingTargetPositionVO.setBeginTime(financingTargetPositionDO.getBeginTime());
//					financingTargetPositionVO.setEmdTime(financingTargetPositionDO.getEmdTime());
//					financingTargetPositionVO.setSortNum(financingTargetPositionDO.getSortNum());
//					financingTargetDO = financingTargetService.get(FinancingTargetDO.class, financingTargetPositionDO.getFinancingTargetId());
//					if (financingTargetDO != null) {
//						financingTargetPositionVO.setTargetName(financingTargetDO.getName());
//						financingTargetPositionVO.setTargetStatus(financingTargetDO.getStatus());
//						financingTargetPositionVO.setCollectAmount(financingTargetDO.getCollectAmount());
//						financingTargetPositionVO.setFinishAmount(financingTargetDO.getFinishAmount());
//						financingTargetPositionVO.setCode(financingTargetDO.getCode());
//						financingTargetPositionVO.setPeriod(financingTargetDO.getPeriod());
//					}
//					financingTargetPositionVOList.add(financingTargetPositionVO);
//				}
//			}
//		}
		return financingTargetPositionVOList;
	}

	@Override
	public boolean delete(FinancingTargetPositionDO financingTargetPosition, String id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean update(FinancingTargetPositionDO financingTargetPosition) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Map<String, Integer> count() {
		List<Map<String, Object>> list = queryDao.selectList("FINANCING_TARGET_POSITION.groupCount", null);
		Map<String, Integer> map = new HashMap();
		if (list != null) {
			for (Map<String, Object> m : list) {
				map.put(m.get("position").toString(), Integer.parseInt(m.get("count").toString()));
			}
		}
		return map;
	}

	@Override
	public List<FinancingTargetPositionDO> findPreparedList(int period) {
		return queryDao.selectList("FINANCING_TARGET_POSITION.findPreparedList", period);
	}

	@Override
	public List<FinancingTargetPositionDO> findByTargetId(String targetId) {
		return queryDao.selectList("FINANCING_TARGET_POSITION.findByTargetId", targetId);
	}
	 
	@Override
	public boolean delete(String id) { 
		return updateDao.delete("FINANCING_TARGET_POSITION.deleteById", id)==1;
	}
}
